boolean press = true;
int xStart, yStart, xEnd, yEnd;

void setup() {
       size(400, 400);
       background(192, 64, 0);
       stroke(255);
     }
    
void draw (){}

void mousePressed() {
int stepX,stepY;
 if(press){
xStart=mouseX;
yStart=mouseY;
press=false;
point(xStart,yStart);
}
else{
xEnd=mouseX;
yEnd=mouseY;
Bresenham(xStart,yStart,xEnd,yEnd);
press=true;
}   
}

void Bresenham(int xStart, int yStart, int xEnd, int yEnd){
  int x, y, dx, dy, d, incE, incNE;
  int stepX=1;
  int stepY=1;
  dx = xEnd - xStart;
  dy = yEnd - yStart;

  if(dx<0){
  stepX=-1;
  }
  if(dy<0){
  stepY=-1;
  }
    x = xStart;
    y = yStart;

if(abs(dx)>abs(dy)){
      println("1");
      println(stepX);
      println(stepY);
  d=2*dy-dx;
  incE=2*dy;
  incNE=2*(dy-dx);
 
  while (x!=xEnd){
      x=x+stepX;
      if (d<=0){
        d = d+incE;
      }
      else {
        y = y+stepY;
        d = d+incNE;
      }
      point(x,y);
    }
}
else{
  println("2");
  println(stepX);
  println(stepY);
  d = 2*dx-dy;
  incE = 2*dx;
  incNE = 2*(dx-dy);
  while (y!=yEnd){
      y = y+stepY;
      if (d<=0){
        d=d+incE;
      }
      else {
        x=x+stepX;
        d=d+incNE;
      }
      point(x,y);
    } 
}
}
